package com.wch.clientdemo.module.base.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 
 * @author WanChengHe 
 * @Date 20181114
 * 数据库帮助类
 */
public class DbHelper extends SQLiteOpenHelper{

	/**
	 * 注意：版本必须要不小于1，不然会报错，具体报错原因可以查看SQLiteOpenHelper的源码
	 */
	private static final String DB_NAME = "test.db";
	private static final int DB_VERSION = 1;
	public DbHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	/**
	 * 该方法用于首次创建
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		//创建表
		db.execSQL("create table notice "
				+ "(id integer primary key autoincrement,"
				+ "notice_id text)");	
	}
	

	/**
	 * 该方法用于数据库需要升级
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		switch (oldVersion) {
		case 1:
			db.execSQL("create table if not existsnotice "
					+ "(id integer primary key autoincrement,"
					+ "notice_id text)");
		}
	}

}
